public class Bank implements Runnable{
    int money = 200;
    @Override
    public void run(){

        if(Thread.currentThread().getName().equals("会计")){
            //存栈
            saveOrTake(300);
        }else if(Thread.currentThread().getName().equals("出纳")){
            //存栈
            saveOrTake(150);
        }
    }
    public synchronized void saveOrTake(int amount){
        if(Thread.currentThread().getName().equals("会计")){
            for(int i = 1;i <= 3;i++){
                money +=amount/3;
                System.out.println("存入了" +amount/3 +"元" + "总共" + money +"元");
                try {
                    Thread.sleep(1000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }
            }
        }else if(Thread.currentThread().getName().equals("出纳")) {
            for (int i = 1; i <= 3; i++) {
                money += amount / 3;
                System.out.println("取出了" + amount / 3 + "元" + "总共" + money + "元");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }



}
